//	Company:	HTHK
//	NAME:	    ProjectCategorySearch.java
//	TITLE:	    The maintence of ProjectCategory in Time Sheet System
//	FUNCTION:	Search from DB of class ProjectCategory associate with the table
//	BY:	        Kodak Xu
//	DATE:	    09/12/2003
//	Update_by	Poly Li
//	Update_date	16-01-2004
// --------------------------------------------------------------
// MODIFICATION HISTORY
// --------------------------------------------------------------
//	CR Log #:  99999  BY:  XXXX   DATE:  dd/mm/yyyy
//	ERROR:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//	FIX:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// --------------------------------------------------------------
package tss.projectcategory;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;

import tss.common.DBServlet2;

public class ProjectCategorySearch extends DBServlet2 
{
	@Override
	protected String perform(HttpServletRequest request,
                             HttpServletResponse response,
                             StrutsMessage message)
    throws  ServletException,
            IOException,
            SQLException,
            DataException,
            Exception
   {		
	  String companyCodeStr = "";
      String projectCategoryNameStr = "";
      //String chargeableStr = "";
	  //String fromStr = "";
	  //String toStr = "";
      if (request.getParameter("company_code") != null)
      	  companyCodeStr = request.getParameter("company_code");
      
      if (request.getParameter("project_category_name") != null)
      	  projectCategoryNameStr = request.getParameter("project_category_name");
/*      
	  if (request.getParameter("chargeable_ind") != null) 
		  chargeableStr = request.getParameter("chargeable_ind");
	  
	  if ((request.getParameter("year_from")!=null && request.getParameter("year_from").length()!=0) && (request.getParameter("month_from")!=null && request.getParameter("month_from").length()!=0)) 
		  fromStr = request.getParameter("year_from")+"/"+request.getParameter("month_from");

	  if ((request.getParameter("year_to")!=null && request.getParameter("year_to").length()!=0) && (request.getParameter("month_to")!=null && request.getParameter("month_to").length()!=0)) 
		  toStr = request.getParameter("year_to")+"/"+request.getParameter("month_to");
*/	  	  
      ProjectCategoryBean projectCategory = ProjectCategoryProcess.createBean();
      projectCategory.setCompany_code(companyCodeStr);
      projectCategory.setProject_category_name(projectCategoryNameStr);
//      projectCategory.setChargeable_ind(chargeableStr);
//	  projectCategory.setEffective_range_from(fromStr);
//	  projectCategory.setEffective_range_to(toStr);
	 
      ProjectCategoryBean[] projectCategorys = ProjectCategoryProcess.find(this.getConnection(),projectCategory);
      
      if (projectCategorys==null || projectCategorys.length==0)
      {
          message.setMessage("No record, please input another criteria.");
          return "tss/projectcategory/ProjectCategorySearch.jsp";
      }
      else if (projectCategorys.length==1)
      {
          request.setAttribute("projectCategory",projectCategorys[0]);
          return "tss/projectcategory/ProjectCategory.jsp?formAction=Update";
      }
      else
      {
          request.setAttribute("projectCategorys",projectCategorys);
          return "tss/projectcategory/ProjectCategoryList.jsp";
      }
   }
}
